package org.rcy.framework.api.entity;

import org.rcy.framework.api.cacheable.CacheAble;
import org.rcy.framework.api.cacheable.CacheKeyStrategy;

/**
 * @author 吴康桥
 * @Description
 * @date 2022/9/27 14:51
 */


public abstract class BaseEntity extends IdEntity implements CacheAble,TypeAliases {
	private static final long serialVersionUID = 1L;
	private static final String CACHE_NAMESPACE = "entity";


	public BaseEntity() {
	}

	public BaseEntity(Long id) {
		super(id);
	}

	public String toString() {
		return this.getId() == null ? super.toString() : this.getClass().getName() + "[id=" + this.id + "]";
	}

	@Override
	public String getNameSpace() {
		return CACHE_NAMESPACE;
	}

	@Override
	public String getCacheKey() {
		String group = this.getClass().getSimpleName().toLowerCase();
		return CacheKeyStrategy.getCacheKey(this.id, new String[]{this.getNameSpace(), group});
	}
}
